package com.kkb.robotcustomerservice.controller;

import com.kkb.robotcustomerservice.util.JsonResult;
import com.kkb.robotcustomerservice.entities.Questions;
import com.kkb.robotcustomerservice.service.QuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author HXH
 */
@RestController
@RequestMapping("/chat")
@CrossOrigin
public class QuestionsController {

    @Autowired
    private QuestionsService questionsService;


    /**
     * 获取问题列表
     */
    @GetMapping("/queryDefaultQuestions")
    public JsonResult<List<Questions>> queryDefaultQuestions(){
        List<Questions> questions = questionsService.getQuestions();
        JsonResult<List<Questions>> jsonResult = new JsonResult<>();
        //获取失败，列表为空
        if (questions.size() == 0) {
            jsonResult.setCode(0);
            jsonResult.setMsg("问题列表为空");
            jsonResult.setSuccess(false);
            jsonResult.setData(null);
            return jsonResult;
        }
        //查询列表成功
        jsonResult.setCode(1);
        jsonResult.setMsg("获取问题列表成功");
        jsonResult.setSuccess(true);
        jsonResult.setData(questions);
        return jsonResult;
    }
}
